import { Suspense } from "react";
import {Switch,Route,Redirect} from 'react-router-dom'
export default function RouterView(props){
    return (
        <Suspense fallback=''>
            <Switch>
                {
                    props.routes.map(item=>{
                        return (
                            <Route key={item.path} path={item.path} component={()=>{
                                if(item.meta.isAuth&&!sessionStorage.getItem('token')){
                                    return <Redirect to='/login'></Redirect>
                                }
                                return <item.component routes={item.children}></item.component>
                            }}></Route>
                        )
                    })
                }
                <Redirect exact from='/' to='/layout/home'></Redirect>
                <Redirect exact from='/layout/my' to='/layout/my/part1'></Redirect>
            </Switch>
        </Suspense>
    )
}